// StateConfig.java
package org.zjx.config;

import org.zjx.core.state.StateComponent;
import org.zjx.core.state.StateValidator;
import org.zjx.core.state.domain.BattleState;
import org.zjx.core.state.domain.PlayerState;

import java.util.List;

/**
 * 状态验证配置加载器
 */
public class StateConfig {

    /**
     * 加载领域状态验证规则
     */
    public static StateValidator loadDomainRules(List<Class<? extends StateComponent>> domainClasses) {
        StateValidator validator = new StateValidator();

        domainClasses.forEach(clazz -> {
            if (clazz == BattleState.class) {
                validator.addDomainRule(clazz, b -> ((BattleState)b).getRoundCount() >= 0);
            } else if (clazz == PlayerState.class) {
                // 添加上限检查 0 <= hp <= 100
                validator.addDomainRule(clazz, p -> {
                    PlayerState ps = (PlayerState)p;
                    return ps.getHp() >= 0 && ps.getHp() <= 100;
                });
            }
            // 添加其他领域类的规则...
        });

        validator.addGlobalRule(StateValidator.UNIQUE_COMPONENT_IDS );
        return validator;
    }
}